class MediaPlayer {
  constructor() {
    this.playlist = [];
    this.currentIndex = 0;
    this.isPiPMode = false;
    this.playbackRate = 1.0;
    this.subtitles = [];
    this.currentSubtitle = null;
  }

  // 播放列表管理
  addToPlaylist(media) {
    this.playlist.push(media);
  }

  removeFromPlaylist(index) {
    this.playlist.splice(index, 1);
  }

  playNext() {
    if (this.currentIndex < this.playlist.length - 1) {
      this.currentIndex++;
      this.playCurrent();
    }
  }

  playPrevious() {
    if (this.currentIndex > 0) {
      this.currentIndex--;
      this.playCurrent();
    }
  }

  playCurrent() {
    // 播放当前索引的媒体
    const media = this.playlist[this.currentIndex];
    console.log('正在播放:', media);
  }

  // 画中画模式
  togglePiP() {
    this.isPiPMode = !this.isPiPMode;
    console.log('画中画模式:', this.isPiPMode ? '开启' : '关闭');
  }

  // 播放速度控制
  setPlaybackRate(rate) {
    this.playbackRate = rate;
    console.log('播放速度设置为:', rate);
  }

  // 字幕支持
  loadSubtitles(subtitles) {
    this.subtitles = subtitles;
  }

  setSubtitle(index) {
    this.currentSubtitle = this.subtitles[index];
  }

  // 媒体元数据
  storeMediaMetadata(metadata) {
    // 存储媒体元数据
    console.log('存储媒体元数据:', metadata);
  }
}

// 导出播放器实例
export const mediaPlayer = new MediaPlayer();